function [] = xmlconCCs2EAPMW()
  % GUI tool to move calibration coefficients given in a SeaBird xmlcon
  % file (database blob or disk file) to the appropriate tables in EAPMW

    DB = DBwrapper('EAPMW');
    if isempty(DB.err)
      % Ask user for location of  xmlcon file
        reply = inputdlg(['Is the xmlcon file a disk file (d) or a database '...
                       'BLOB (b)?'], 'XMLCON File Origin', 1, {'b'}, 'on');
        if strcmp(reply, 'b')
          % Generate list of available CONfileBLOBs
            try
                q = query(DB, struct('tbls', {{'MatlabCTDProcessing'}},...
                                   'cols', {{'CONFileName', 'CONFileBLOB'}}...
                                   ));
                q.submitStatement
                if ~isempty(q.errCode) 
                    error(['Sorry, "' [q.errCode{:}] '" trying to open '...
                           'EAPMW; this error is fatal, aborting.'])
                end
                bad = cellfun(@isempty, q.result(:,2)) | ...
                      strcmp(q.result(:,2), 'null');
                q.result = q.result(~bad,:);
                [~, where, ~] = unique(q.result(:,2));
                uniqueBlobs = q.result(where,2);
                uniqueBlobFNs = q.result(where,1);
                blobListPanel = uipanel('Title', ['Available BLOBs and '...
                                      'they''re names in the database'],...
                                      'FontSize', 11);
                if isdeployed
                    set(blobListPanel, 'Visible', 'off')
                else
                    set(blobListPanel, 'Visible', 'on')
                end
                set(gcf, 'DefaultUicontrolUnits', 'Normalized')
                fnList = uicontrol('Parent', blobListPanel,...
                                   'Style', 'listbox',...
                                   'Position', [0.05 0.15 0.4 0.8],...
                                   'String', uniqueBlobFNs);
                blobList = uicontrol('Parent', blobListPanel,...
                                     'Style', 'listbox',...
                                     'Position', [0.55 0.15 0.4 0.8],...
                                     'String', uniqueBlobs);
                doneButton = uicontrol('Parent', blobListPanel,...
                                       'Style', 'pushbutton',...
                                       'Position', [0.45 0.03 0.1 0.08],...
                                       'HorizontalAlignment', 'Center',...
                                       'String', 'Done',...
                                       'Callback', {@(varargin) delete(get(...
                                                 blobListPanel, 'Parent')),...
                                                 @uiresume});
                set(blobListPanel, 'Visible', 'on')
                f = fileWrapper('.\temp.xmlcon', 'w');
                ucm = uicontextmenu;
                m1 = uimenu(ucm, 'Label', 'Write', 'Callback', {@Write,...
                            uniqueBlobs{get(blobList, 'Value')}, f});%...
                m2 = uimenu(ucm, 'Label', 'Examine', 'Callback', {@Examine,...
                            uniqueBlobs{get(blobList, 'Value')}, f});
                set(blobList, 'uicontextmenu', ucm)
                uiwait
            catch ME
                errordlg(ME.message, 'DB Error!', 'modal')
                cleanUp;
                return
            end
        else
          % Get file
            [fn, pn, ~] = uigetfile('*.xmlcon', ['Please choose one or more '...
                                    'xmlcon files'], '', 'MultiSelect', 'on');
            f = fileWrapper(fullfile(pn, fn), 'r');
        end
        tmp = myReadXMLFile(f.name);
        switch 1
            case regexp(tmp.Instrument_Name', 'SBE 25')
                p = ProcessSBE25xmlcon(f);
            otherwise
                p = 'Sorry, not yet implemented';
        end
        if ismethod(p, 'unpackXMLCON') && isempty(p.err)
            p.unpackXMLCON;
        else
            errordlg(p, 'NYI Error!', 'modal')
            cleanUp;
            return
        end
        f.close;
        if strcmp(f.permission, 'w')
            f.delete;
        end
    else
        errordlg(['Sorry, "' [DB.err{:}] '" trying to open EAPMW.  This error '...
                'is fatal, aborting.'], 'DB Error!', 'modal')
    end
    cleanUp;
end

function Write(varargin)
    BLOB2file(varargin{end-1}, varargin{end})
    varargin{end}.close;
    uiresume
end

function Examine(varargin)
    BLOB2file(varargin{end}, '.\temp.xmlcon')
    edit('.\temp.xmlcon');
end

function cleanUp
    fclose('all');
    close('all');
    clear variables;
end